﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace RemoteTestRunner.Contracts
{
    [DataContract()]
    public class TestResultInfo
    {
        #region Private Attributes

        private bool _passed;

        #endregion

        #region Constructors

        public TestResultInfo()
        {
            TestId = string.Empty;
            Outcome = string.Empty;
            MethodName = string.Empty;
            Message = "Passed";
            StackTrace = string.Empty;
            ClassName = string.Empty;
            DataDrivenResults = new List<TestResultInfo>();
        }

        #endregion

        #region Properties

        [DataMember()]
        public string TestId { get; set; }

        [DataMember()]
        public string ExecutionId { get; set; }

        [DataMember()]
        public string Outcome { get; set; }

        [DataMember()]
        public string MethodName { get; set; }

        [DataMember()]
        public string Message { get; set; }

        [DataMember()]
        public string StackTrace { get; set; }

        [DataMember()]
        public string ClassName { get; set; }

        [DataMember()]
        public bool IsDataDriven { get; set; }

        [DataMember()]
        public string ResultType { get; set; }

        [DataMember()]
        public int DataRowInfo { get; set; }

        [DataMember()]
        public List<TestResultInfo> DataDrivenResults { get; set; }

        [DataMember()]
        public bool Passed
        {
            get
            {
                return string.Compare(this.Outcome, "Passed", true) == 0;
            }

            set
            {
                // This property is implemented for WCF support only - it is not actually
                // used by the caller
                _passed = value;
            }
        }

        #endregion

        #region Overridden Methods

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            return string.Format(
                "{0} - {1}: {2}\r\n\r\nStack Trace: {3}\r\n\r\nTest Class: {4}",
                MethodName,
                Outcome,
                Message,
                StackTrace.Trim().Replace("at ", string.Empty),
                ClassName).Replace("Stack Trace: \r\n\r\n", string.Empty);
        }

        #endregion
    }

}
